package com.esinhai.tz.controller;

import com.esinhai.tz.common.Const;
import com.esinhai.tz.common.ServerResponse;
import com.esinhai.tz.pojo.UserTz;
import com.esinhai.tz.pojo.UserTzWithBLOBs;
import com.esinhai.tz.service.IUserTzService;
import com.esinhai.tz.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * Created by 32988 on 2018/4/12.
 */
@Controller
@RequestMapping("/userTz")
@CrossOrigin
public class UserTzController {

    @Autowired
    private IUserTzService iUserTzService;

    /**
     * 上传IDCard信息 包含图
     * @param session
     * @param imgFiles
     * @param faceFiles
     * @return
     */
    @RequestMapping(value = "uploadUserInfo.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<UserTzWithBLOBs> uploadUserInfo(HttpSession session ,
                                 @RequestParam("imgFiles") MultipartFile [] imgFiles,
                                 @RequestParam("faceFiles") MultipartFile [] faceFiles){
        ServerResponse<UserTzWithBLOBs> userTzWithBLOBsServerResponse = iUserTzService.saveUserInfo(imgFiles,faceFiles);
        return userTzWithBLOBsServerResponse;
    }

    /**
     * 查询IDCard信息
     * @param userTz
     * @return
     */
    @RequestMapping(value = "queryUserInfo.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<List<Map<String, Object>>> queryUserInfo(UserTz userTz){
        ServerResponse<List<Map<String, Object>>> listServerResponse = iUserTzService.queryUserInfo(userTz);
        return listServerResponse;
    }



    /**
     * TODO 更新功能
     * @param userTz
     * @return
     */
    @RequestMapping(value = "updateUserInfo.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<List<Map<String, Object>>> updateUserInfo(UserTz userTz){
        //ServerResponse<List<Map<String, Object>>> listServerResponse = iUserTzService.queryUserInfo(userTz);
        return null;
    }

    /**
     * 人脸注册接口
     * @param imgFiles
     * @param faceFiles
     * @return
     */

    @RequestMapping(value = "saveWebServiceFrontImages.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> saveWebServiceFrontImages(@RequestParam("imgFiles") MultipartFile [] imgFiles,
                                                         @RequestParam("faceFiles") MultipartFile [] faceFiles){


        return iUserTzService.saveWebServiceFrontImages(imgFiles,faceFiles);
    }

    /**
     * 查询IDCard图片访问地址
     * @param userTz
     * @return
     */
    @RequestMapping(value = "queryUserFaceInfo.do",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryUserFaceInfo(UserTz userTz){
        return iUserTzService.queryUserFaceInfo(userTz);
    }

    /**
     * 查询IDCard图片访问地址
     * @param
     * @return
     */
    @RequestMapping("/{idcard}/idcard")
    @ResponseBody
    @CrossOrigin
    public Map<String, Object> queryUserFaceInfoByIdCard(@PathVariable("idcard")String idcard){
        return iUserTzService.queryUserFaceInfo(idcard);
    }

    /**
     * 删除IDCard信息
     * @param objectId
     * @return
     */
    @RequestMapping(value = "deleteUserInfo.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String > queryUserInfo(String objectId){
        ServerResponse<String> listServerResponse = iUserTzService.deleteUserInfo(objectId);
        return listServerResponse;
    }

}
